package com.sdygmedia.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.sdygmedia.domain.Page;
import com.sdygmedia.service.PageService;

@Controller
public class PageAction extends ActionSupport {

	private Page page;
	@Resource
	private PageService pageService;
	
	public String addUI() throws Exception {
		return "addUI";
	}
	
	public String add() throws Exception {
		pageService.save(page);
		return "add";
	}
	
	public String delete() throws Exception {
		pageService.delete(page.getId());
		return "delete";
	}
	
	public String updateUI() throws Exception {
		Page pageUp = pageService.getById(page.getId());
		ActionContext.getContext().put("pageUp", pageUp);
		
		return "updateUI";
	}
	
	public String update() throws Exception {
		pageService.update(page);
		return "update";
	}
	
	public String list() throws Exception {
		
		List pageList = pageService.findAll();
		ActionContext.getContext().put("pageList", pageList);
		
		return "list";
	}

	
	
	//-----------------------------------------
	public PageService getPageService() {
		return pageService;
	}

	public void setPageService(PageService pageService) {
		this.pageService = pageService;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}
	
}
